VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Send E Mails From Ur Machine Using GMail { Google } Server.

by Gehan Fernando (47 Submissions)
Category: Internet/HTML
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Sat 8th September 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Send E Mails From Ur Machine Using GMail { Google } Server.

API Declarations



Imports System.Net
Imports System.Net.Mail
Imports System.Configuration
Imports System.Text.RegularExpressions

#Region "Send Mails Using GMail Server"
REM Author :- Gehan Fernando
REM Date :- 09th August 2007
REM Description :-
#End Region

Rate Send E Mails From Ur Machine Using GMail { Google } Server.




    Private _MMsg As Net.Mail.MailMessage
    Private _EServer As Net.Mail.SmtpClient
    Private _Cred As NetworkCredential

    Private _tmail As String = ""
    Private _cmail As String = ""
    Private _sub As String = ""
    Private _msg As String = ""

    Private _img As Image = Image.FromFile(Application.StartupPath + "\Ms.jpg")
    Private _i As Int16 = 0


    Private Sub ButtonSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSend.Click

        Try

            TimerImage.Enabled = True
            Call TimerImage_Tick(sender, e)
            Application.DoEvents() : Me.Refresh()

            If TextBoxTo.Text.ToString().Trim().Length = 0 Then ' Check To Mail ID Validation
                MessageBox.Show("E-Mail Cannot Be Empty", "Mail Sender", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                TimerImage.Enabled = False : _i = 0
                TextBoxTo.Focus()
                Exit Sub
            Else
                If IsValidEMailAddress(TextBoxTo.Text.ToString()) = True Then
                    _tmail = TextBoxTo.Text.ToString()
                Else
                    MessageBox.Show("Not Valid E-Mail", "Mail Sender", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    TimerImage.Enabled = False : _i = 0
                    TextBoxTo.Focus()
                    Exit Sub
                End If
            End If

            _sub = TextBoxSubject.Text.ToString().Trim()
            _msg = TextBoxMessage.Text.ToString().Trim()

            _MMsg = New Net.Mail.MailMessage("[email protected]", _tmail.ToString())

            With _MMsg
                .Subject = _sub
                .Body = _msg
                .IsBodyHtml = False
                .Priority = MailPriority.High
            End With

            _EServer = New Net.Mail.SmtpClient("smtp.gmail.com", "587")
            _EServer.EnableSsl = True
            _Cred = New Net.NetworkCredential("gmailuraccountid", "gmailaccountpassword")
            _EServer.Credentials = _Cred
            _EServer.Send(_MMsg)

            MessageBox.Show("Mail Send Successfully ...", "Mail Sender", MessageBoxButtons.OK, MessageBoxIcon.Information)
            TimerImage.Enabled = False : _i = 0
            _MMsg.Dispose()
        Catch ex As Exception
            MessageBox.Show(ex.Message.ToString(), "Mail Sender", MessageBoxButtons.OK, MessageBoxIcon.Error)
            TimerImage.Enabled = False : _i = 0
            _MMsg.Dispose()
        End Try

    End Sub

    Private Sub TimerImage_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerImage.Tick

        TimerImage.Interval = 500
        If _i = 0 Then
            _img.RotateFlip(RotateFlipType.Rotate180FlipY)
            _i = 1
        Else
            _img.RotateFlip(RotateFlipType.Rotate90FlipY)
            _i = 0
        End If

        PictureBoxRotate.Image = _img

    End Sub

    Public Shared Function IsValidEMailAddress(ByVal emailAddress As String) As Boolean
        Return Regex.IsMatch(emailAddress, "^([\w-]+\.)*?[\w-]+@[\w-]+\.([\w-]+\.)*?[\w]+$")
    End Function

End Class

Download this snippet    Add to My Saved Code

Send E Mails From Ur Machine Using GMail { Google } Server. Comments

No comments have been posted about Send E Mails From Ur Machine Using GMail { Google } Server.. Why not be the first to post a comment about Send E Mails From Ur Machine Using GMail { Google } Server..

Post your comment

Subject:
Message:
0/1000 characters